<style type="text/css">
.wd-section { clear:both; width: 100%; border:#2DBA02 solid 1px; display: none; padding: 10px}
.wd-tab .wd-item li{background-color:#f2f2f2;float:left;font-weight:bolder;margin-right:2px; padding:.5em 1em; list-style: none;}
.wd-tab .wd-item li.wd-current{background-color:#2DBA02;}
.wd-tab .wd-item li.wd-current a{color:#fff !important;}
.wd-tab .wd-item li a:link, .wd-tab .wd-item li a:visited{color:#000;}
.wd-tab .wd-item li a:hover{color:#c00;}
.wd-tab .wd-panel{padding-right:15px;}
.wd-tab .wd-panel h3, .wd-tab .wd-panel h4, .wd-tab .wd-panel h5, .wd-tab .wd-panel ul, .wd-tab .wd-panel ol, .wd-tab .wd-panel p{margin-bottom:1em;}
.wd-tab .wd-panel h3, .wd-tab .wd-panel h4, .wd-tab .wd-panel h5{font-size:1em;}
.wd-tab .wd-panel ul, .wd-tab .wd-panel ol{margin-left:3em;margin-right:3em;}
.wd-tab .wd-panel li{padding:.1em 0;}
.wd-tab .wd-panel ul{list-style:disc;}
.wd-tab .wd-panel ol{list-style:decimal;}
</style>
<div id="tnm-body">
    	<div class="tnm-col-left">
        	<h2 class="title-tnm-col-left">Báo cáo thu chi tháng <?php echo $currentMonth ?></h2>
            <div class="content-tnm-col-left">
            <div class="wd-tab">
            	<ul class="wd-item">
            		<li><a href="#wd-fragment-1">Thu</a></li>
            		<li><a href="#wd-fragment-2">Chi</a></li>
            		<li><a href="#wd-fragment-3">Biểu đồ</a></li>            		
            	</ul>
            	<div class="wd-panel">
            		<div class="wd-section" id="wd-fragment-1">
    				<div class="dialog-new">
                    <?php $form=$this->beginWidget('CActiveForm', array(
                        	'id'=>'search-import',
                        	'enableAjaxValidation'=>false,
                        )); ?>
                        <div class="style-form">                            
                            <dl>
                                <dt>Từ ngày:</dt>
                                <dd>
                                <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                        'name'=>'fromDateImport',
                                        'value' => '01-'.$currentMonth,
                                        'options'=>array('dateFormat'=>'dd-mm-yy'),
                                    ));?>
                                </dd> 
                                
                            </dl>
                            <dl>
                                <dt>Đến ngày:</dt>
                                <dd>
                                <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                        'name'=>'endDateImport',
                                        'value' => date('t', strtotime( "01-" . $currentMonth ) ). '-'.$currentMonth,
                                        'options'=>array('dateFormat'=>'dd-mm-yy'),
                                    ));?>
                                </dd> 
                                
                            </dl>
                            <dl>
                                <dt></dt>
                                <dd>
                                    <div class="button"><a href="#">Kết quả</a></div>
                                </dd>                  
                            </dl>
                        </div>
                    <?php $this->endWidget(); ?>
                </div>
                    <div id="import_result">
                    <?php 
                    
                    function get_real_value($item)
                    {
                        $money = unserialize($item);
                        return Yii::app()->numberFormatter->format('###,###,###,###', $money['payment']) . ' VNĐ';
                         
                    }
                    $this->widget('zii.widgets.grid.CGridView', array(
                        'id'=>'supplies-import-grid',
                        'dataProvider'=>$import,
                        //'filter'=>$model,
                        'afterAjaxUpdate'=>'function(id,data){ 
                            $(".items tr td a").click(function(){
                               $("#hidden_div").empty().load($(this).attr("href")).dialog({modal : true});
                               return false;
                            });
                        }',
                        'summaryText' => 'Tổng tiền : '. Yii::app()->numberFormatter->format('###,###', $money_import) .'VNĐ. Hiển thị kết quả từ {start} - {end}.' ,

                        'columns'=>array(
                       
                        array(
                            'name' => 'time',
                            'value' => 'date("d-m-Y",strtotime($data->time))'                        
                        ),
                         array(
                            'name' => 'Tiền',
                			'type'=>'raw',
			                 'value' => 'CHtml::link(CHtml::encode(get_real_value($data->data)),array("detail","id"=>$data->id))',
                        ),
                        )
                    )); 
                    ?> 
                    </div> 
            		</div>
            		<div class="wd-section" id="wd-fragment-2">
            			<div class="dialog-new">
                        <?php $form=$this->beginWidget('CActiveForm', array(
                            	'id'=>'search-export',
                            	'enableAjaxValidation'=>false,
                            )); ?>
                            <div class="style-form">                            
                                <dl>
                                    <dt>Từ ngày:</dt>
                                    <dd>
                                    <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                            'name'=>'fromDateExport',
                                            'value' => '01-'.$currentMonth,
                                            'options'=>array('dateFormat'=>'dd-mm-yy'),
                                        ));?>
                                    </dd> 
                                    
                                </dl>
                                <dl>
                                    <dt>Đến ngày:</dt>
                                    <dd>
                                    <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                            'name'=>'endDateExport',
                                            'value' => date('t', strtotime( "01-" . $currentMonth ) ). '-'.$currentMonth,
                                            'options'=>array('dateFormat'=>'dd-mm-yy'),
                                        ));?>
                                    </dd> 
                                    
                                </dl>
                                <dl>
                                    <dt></dt>
                                    <dd>
                                        <div class="button"><a href="#">Kết quả</a></div>
                                    </dd>                  
                                </dl>
                            </div>
                        <?php $this->endWidget(); ?>
                    </div>
                    <div id="export_result">
                    <?php 
                    $this->widget('zii.widgets.grid.CGridView', array(
                        'id'=>'supplies-export-grid',
                        'dataProvider'=>$export,
                        //'filter'=>$model,
                        'summaryText' => 'Tổng tiền : '. Yii::app()->numberFormatter->format('###,###', $money_export) .'VNĐ. Hiển thị kết quả từ {start} - {end}.' ,
                        'columns'=>array(
                        array(
                            'name' => 'supply_id',
                            'value' =>  '$data->Supply->name'   
                        ),
                        'other',
                        'price',
                        'number',
                        'created',                        
                        ),
                    )); 
                    ?> 
                    </div>
            		</div>
            		<div class="wd-section" id="wd-fragment-3">
        			<?php 
                     $flashChart = Yii::createComponent('ext.yiiopenflashchart.EOFC2'); 
                    
                     // Minimum usage. You will always need at least this.
                    $flashChart->begin('SteppChart');
                    $flashChart->setTitle('Doanh thu tháng ' .$currentMonth,'{color:#880a88;font-size:15px;padding-bottom:20px;}');
                    $max = 0;
                    foreach ($getMoney as $key => $money) {
                        $data[$key]['Day']['date'] = '' . $key;
                        $data[$key]['Day']['count'] = $money;
                        if($max < $money)
                            $max = $money;
                    }
                    
                    //print_r($data);
                    
                    $flashChart->setData($data);
                    $flashChart->setNumbersPath('{n}.Day.count');
                    $flashChart->setLabelsPath('default.{n}.Day.date');
                    
                    $flashChart->setLegend('x','Ngày');
                    $flashChart->setLegend('y','Tiền (Đơn vị Nghìn VNĐ)', '{color:#AA0aFF;font-size:12px;}');
                    
                    $flashChart->axis('x',array('tick_height' => 5,'3d' => -10));
                    //$flashChart->axis('x',array('range' => array(1,31,1)));
                    $flashChart->axis('y',array('range' => array(0,floor($max*1.2),$max/5)));
                    
                    $flashChart->renderData();
                    $flashChart->render(800,420);
                 ?>
            		</div>
            	</div>
            </div>
            
                 
            </div>
            <div class="bottom-tnm-col-left"></div>
        </div>
        <div class="tnm-col-right">
        	<h2 class="title-tnm-col-right">Báo cáo theo tháng</h2>
            <div class="content-tnm-col-right">
            	<div id="sub-col-right">
                	 <ul class="actions">
                        <?php foreach($months as $month): ?>
                        <li><a href="<?php echo $this->createUrl('/reports/view',array('month' => $month)) ?>">Tháng <?php echo $month ?></a></li>	
                        <?php endforeach; ?>
                    </ul>                	
                </div>
            </div>
            <div class="bottom-tnm-col-right"></div>
        </div>
    </div>
<div id="hidden_div"></div>    
<script type="text/javascript">

$().ready(function(){
    $('.items tr td a').click(function(){
       $('#hidden_div').empty().load($(this).attr('href')).dialog({modal : true});
       return false;
    });
    // tabs
    $('.wd-tab').each(function(){
    	$(this).find('.wd-section').hide();
    
    	var current = $(this).find('.wd-item').children('.wd-current');
    	if (current.length == 0){
    		$(this).find('.wd-item').children(':first-child').addClass('wd-current');
    		$($(this).find('.wd-item').children(':first-child').find('a').attr('href')).show();
    	}
    
    	$(this).find('.wd-item').find('a').click(function(){
    		var current = $(this).parent().hasClass('wd-current');
    		if (current == false){
    			$(this).parent()
    				.addClass('wd-current')
    				.siblings().each(function(){
    					$(this).removeClass('wd-current');
    					$($(this).find('a').attr('href')).hide();
    				});
    			$($(this).attr('href')).fadeIn();
    		}
    		return false;
    	});
    });	
    
    // import
    $('#search-import .button').click(function(){
        var url = '<?php echo $this->createUrl('/reports/import') ?>/from/' + $('#fromDateImport').val() + '/to/' + $('#endDateImport').val() ;
        $('#import_result').empty('Loading...');
        $.post(url,function(resp){
            //alert(resp);
            $('#import_result').html(resp).fadeIn();
        });
    });
    
    // export
    $('#search-export .button').click(function(){
        var url = '<?php echo $this->createUrl('/reports/export') ?>/from/' + $('#fromDateExport').val() + '/to/' + $('#endDateExport').val() ;
        $('#export_result').empty();
        $.post(url,function(resp){
            //alert(resp);
            $('#export_result').html(resp).fadeIn();
        });
    });
    
});
</script>